package app

import (
	"fmt"

	"gitee.com/zawei/yggdrasil/pkg/registry"
)

type Option func(*Application) error

func WithHook(stage Stage, fns ...func() error) Option {
	return func(app *Application) error {
		hooks, ok := app.hooks[stage]
		if ok {
			hooks.Register(fns...)
			return nil
		}
		return fmt.Errorf("hook stage not found")
	}
}

func WithBeforeStopHook(fns ...func() error) Option {
	return WithHook(StageBeforeStop, fns...)
}

func WithAfterStopHook(fns ...func() error) Option {
	return WithHook(StageAfterStop, fns...)
}

func WithRegistry(registry registry.Registry) Option {
	return func(app *Application) error {
		app.registry = registry
		return nil
	}
}
